﻿using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ProjectCore.Application;
using ProjectCore.Application.AppUser.Dto;
using ProjectCore.Common;
using ProjectCore.Domain.Model.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ProjectCore.WebApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [EnableCors("any")]
    public class ProductController : ControllerBase
    {
        private readonly IAppProduct appProduct;
        public ProductController(IAppProduct _appAdmin)
        {
            appProduct = _appAdmin;
        }

        /// <summary>
        /// 获取商品表集合
        /// </summary>
        /// <returns></returns>
        
        [HttpGet]
        public async Task<ActionResult> GetProducts(int Tid=0, int Sta=0, string Na="", int pageIndex=1, int pageSize=5)
        {
            Task<HeaderResult<List<PproductType>>> pproductTypes = appProduct.GetPproductTypes(Tid,Sta,Na,pageIndex,pageSize);
            return Ok(new { data = await pproductTypes });
        }


        /// <summary>
        /// 商品表逻辑删除
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> IsDel(int Id)
        {
            Task<int> n = appProduct.IsDel(Id);
            return Ok(new { data = await n });
        }


        /// <summary>
        /// 商品表添加
        /// </summary>
        /// <param name="product"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> AddProduct(Product product)
        {
            Task<int> n = appProduct.AddProduct(product);
            return Ok(new
            {
                data = await n
            });
        }


        /// <summary>
        /// 获取商品表数据
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetProduct(int Id)
        {
            Task<Product> product = appProduct.GetProduct(Id);
            return Ok(new
            {
                data = await product
            });
        }


        /// <summary>
        /// 修改商品表数据
        /// </summary>
        /// <param name="product"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> UptProduct(Product product)
        {
            Task<int> n = appProduct.UptProduct(product);
            return Ok(new
            {
                data = await n
            });
        }


        /// <summary>
        /// 汽车规格添加
        /// </summary>
        /// <param name="skuCar"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> SkuCarAdd(SkuCar skuCar)
        {
            Task<int> n = appProduct.SkuCarAdd(skuCar);
            return Ok(new
            {
                data = await n
            });
        }


        /// <summary>
        /// 获取汽车规格数据
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetCar(int Id)
        {
            Task<SkuCar> car = appProduct.GetCar(Id);
            return Ok(new
            {
                data = await car
            });
        }


        /// <summary>
        /// 修改汽车规格数据
        /// </summary>
        /// <param name="car"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> SkuCarUpt(SkuCar car)
        {
            Task<int> n = appProduct.SkuCarUpt(car);
            return Ok(new
            {
                data = await n
            });
        }


        /// <summary>
        /// 手机规格添加
        /// </summary>
        /// <param name="phone"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> SkuPhoneAdd(SkuPhone phone)
        {
            Task<int> n = appProduct.SkuPhoneAdd(phone);
            return Ok(new
            {
                data = await n
            });
        }


        /// <summary>
        /// 获取手机规格数据
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetPhone(int Id)
        {
            Task<SkuPhone> phone = appProduct.GetPhone(Id);
            return Ok(new
            {
                data = await phone
            });
        }


        /// <summary>
        /// 修改手机规格数据
        /// </summary>
        /// <param name="phone"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> SkuPhoneUpt(SkuPhone phone)
        {
            Task<int> n = appProduct.SkuPhoneUpt(phone);
            return Ok(new
            {
                data = await n
            });
        }


        /// <summary>
        /// 设置添加
        /// </summary>
        /// <param name="setting"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> SettingAdd(Setting setting)
        {
            Task<int> n = appProduct.SettingAdd(setting);
            return Ok(new
            {
                data = await n
            });
        }


        /// <summary>
        /// 获取设置数据
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetSetting(int Id)
        {
            Task<Setting> setting = appProduct.GetSetting(Id);
            return Ok(new
            {
                data = await setting
            });
        }


        /// <summary>
        /// 修改设置数据
        /// </summary>
        /// <param name="setting"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> SettingUpt(Setting setting)
        {
            Task<int> n = appProduct.SettingUpt(setting);
            return Ok(new
            {
                data = await n
            });
        }
    }
}
